package com.gin.kotlin.gf2gamecommunity.base

import android.util.Log
import okhttp3.Interceptor
import okhttp3.Response

class LogInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val t0 = System.currentTimeMillis()
        val request = chain.request()

        Log.d(TAG, "${request.method} 请求开始 URL: ${request.url}")
        val response = chain.proceed(request)
        val t1 = System.currentTimeMillis()
        Log.d(TAG, "${request.method} 请求结束 URL: ${request.url} 耗时: ${t1 - t0} 毫秒 code: ${response.code}")
        return response
    }

    companion object {
        private val TAG = LogInterceptor::class.java.simpleName
    }
}